{extend name="common:frm_base" /}
{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">心愿标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">心愿发布人</label>
                    <div class="layui-input-block">
                        <input type="text" name="realname" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body" id="layer-photos-demo">
            <script type="text/html" id="statusTpl">
                {{#  if(d.status == 1){ }}
                <input type="checkbox" lay-filter="status_change" field="status" table_name="wish"
                       id="{{d.id}}" checked lay-skin="switch" lay-text="开启|关闭">
                {{#  } else { }}
                <input type="checkbox" lay-filter="status_change" field="status" table_name="wish"
                       id="{{d.id}}" lay-skin="switch" lay-text="开启|关闭">
                {{#  } }}
            </script>
            <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
            <script type="text/html" id="userTpl">
                <img style="display: inline-block; height: 100%;" src={{ d.head_pic }}>
                {{d.nickname}}
            </script>
            <script type="text/html" id="prove">
                {{#  if(d.prove){ }}
                <img onclick="big_img('{{ d.prove }}');"  style="display: inline-block; height: 100%;" src={{ d.prove }}>
                {{# } }}
            </script>

            <script type="text/html" id="titleTpl">
                <a lay-href="/admin/wish/add?id={{d.wish_id}}">
                 {{d.title}}
                </a>
            </script>
            <script type="text/html" id="table-useradmin-webuser">
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del_apply"><i
                class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>

<script>


    layui.config({
        base: '__LAYUIADMIN__/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table;

        //监听搜索
        form.on('submit(LAY-user-front-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('LAY-user-manage', {
                where: field
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        layer.photos({
            photos: '#layer-photos-demo'
            ,anim:0
        });

        //用户管理
        table.render({
            elem: '#LAY-user-manage'
            , url: "{:url('wish/ajaxApplyList')}" //模拟接口
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'id', width: 100, title: 'ID', sort: true}
                , {field: 'title', title: '心愿标题', minWidth: 100, toolbar:'#titleTpl'}
                , {field: 'v_mobile', title: '志愿者联系方式', minWidth: 100}
                , {field: 'real_name', title: '心愿发布人', minWidth: 100}
                , {field: 'nickname', title: '认领人', minWidth: 100, toolbar:'#userTpl'}
                , {field: 'realname', title: '姓名', minWidth: 100}
                , {field: 'mobile', title: '联系方式', minWidth: 100}
                , {field: 'c_time', title: '认领时间'}
                , {field: 'prove', title: '认领凭证', toolbar:'#prove'}
                , {field: 's_time', title: '认领人确认时间'}
                , {field: 'co_time', title: '被认领人确认时间'}
                , {title: '操作', width:180, align: 'center', fixed: 'right', toolbar: '#table-useradmin-webuser'}
            ]]
            , method: 'post'
            , page: true
            , limit: 20
            , height: 'full-130'
            , text: '对不起，加载出现异常！'
        });

        $('.layui-btn.layuiadmin-btn-useradmin').on('click', function () {
            var type = $(this).data('type');
            var url = "";
            if (type == 'add') {
                url = "{:url('wish/add')}";
            }
            active[type] ? active[type].call(this, url, table) : '';
        });
    });
    function big_img(img){
        var json= {
            "title": "", //相册标题
            "id": 123, //相册id
            "start": 0, //初始显示的图片序号，默认0
            "data": [ //相册包含的图片，数组格式
                {
                    "alt": "图片名",
                    "pid": 0, //图片id
                    "src": img, //原图地址
                    "thumb": "" //缩略图地址
                }
            ]
        }
        layer.photos({
            photos: json
            ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
        });
    }
</script>
</body>
</html>
{/block}
